package com.csthink.auditlog.config.listener;

import com.csthink.auditlog.domain.AuditLog;
import com.csthink.auditlog.domain.AuditLogEvent;
import org.springframework.context.ApplicationListener;

/**
 * When extends this AbstractAuditLogListener, and make it a bean in Spring
 * context, the Listener can receive AuditLogEvent, then handle it.
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
public abstract class AbstractAuditLogListener implements ApplicationListener<AuditLogEvent>  {

    /**
     * Should implement save work.
     */
    protected abstract void save(AuditLog auditLog);

    @Override
    public void onApplicationEvent(AuditLogEvent event) {
        save(event.getSource());
    }
}
